use ""

********************************************************************************
*figure 1 - histogram of religiosity by denominational group
********************************************************************************

*figure
histogram religiosity01, by(denom) percent bin(10) xlabel(.05 "1" .15 "2" .25 "3" .35 "4" .45 "5" .55 "6" .65 "7" .75 "8" .85 "9" .95 "10", labcolor(black*.9)) ylabel(0 "0%" 10 "10%" 20 "20%" 30 "30%" 40 "40%" 50 "50%", labcolor(black*.9)) ytitle(" " ) xtitle("Deciles") ztitle(" ")

********************************************************************************
*table A1 / figure 2 - marginal effect plot for coefficients
********************************************************************************

*figure
regress sorting religiosity01 white_evang prot cath jew secu interest sophistication abortion  govspend male white black age educ7cat oldsouth _88  _92  _94  _96  _00 _08  _12 [pweight= vcf0010z], robust  
est store m1
regress sorting religiosity01 white_evang prot cath jew secu interest sophistication abortion  govspend male white black age educ7cat oldsouth _88  _92  _94  _96  _00 _08  _12 [pweight= vcf0010z] if pid3==1, robust  
est store m2
regress sorting religiosity01 white_evang prot cath jew secu interest sophistication abortion  govspend male white black age educ7cat oldsouth _88  _92  _94  _96  _00 _08  _12 [pweight= vcf0010z] if pid3==3, robust  
est store m3
coefplot m1 m2 m3, xline(0) drop(interest male white black age educ7cat oldsouth _88  _92  _94  _96  _00 _08  _12 _cons)

*table
regress sorting religiosity01 white_evang prot cath jew secu interest abortion govspend sophistication male white black age educ7cat oldsouth _88  _92  _94  _96  _00  _08  _12 [pweight= vcf0010z], robust
outreg, se bdec(2) starloc(1) replace
regress sorting religiosity01 white_evang prot cath jew secu interest abortion govspend sophistication male white black age educ7cat oldsouth _88  _92  _94  _96  _00  _08  _12 [pweight= vcf0010z] if pid3==1, robust
outreg, se bdec(2) starloc(1) merge
regress sorting religiosity01 white_evang prot cath jew secu interest abortion govspend sophistication male white black age educ7cat oldsouth _88  _92  _94  _96  _00  _08  _12 [pweight= vcf0010z] if pid3==3, robust
outreg, se bdec(2) starloc(1) merge

*alternative sorting metric
regress sortingalt religiosity01 white_evang prot cath jew secu interest abortion govspend sophistication male white black age educ7cat oldsouth _88  _92  _94  _96  _00  _08  _12 [pweight= vcf0010z], robust
outreg, se bdec(2) starloc(1) replace
regress sortingalt religiosity01 white_evang prot cath jew secu interest abortion govspend sophistication male white black age educ7cat oldsouth _88  _92  _94  _96  _00  _08  _12 [pweight= vcf0010z] if pid3==1, robust
outreg, se bdec(2) starloc(1) merge
regress sortingalt religiosity01 white_evang prot cath jew secu interest abortion govspend sophistication male white black age educ7cat oldsouth _88  _92  _94  _96  _00  _08  _12 [pweight= vcf0010z] if pid3==3, robust
outreg, se bdec(2) starloc(1) merge

********************************************************************************
*table A2 / figure 3 - yearly regs for m.e. of relig over time 
********************************************************************************

*table
regress sorting religiosity01 pid3 pidxrelig white_evang prot cath jew secu interest abortion govspend sophistication male white black age educ7cat oldsouth[pweight= vcf0010z] if year==1984, robust
outreg, se bdec(2) starloc(1) replace
regress sorting religiosity01 pid3 pidxrelig white_evang prot cath jew secu interest abortion govspend sophistication male white black age educ7cat oldsouth[pweight= vcf0010z] if year==1988, robust
outreg, se bdec(2) starloc(1) merge
regress sorting religiosity01 pid3 pidxrelig white_evang prot cath jew secu interest abortion govspend sophistication male white black age educ7cat oldsouth[pweight= vcf0010z] if year==1992, robust
outreg, se bdec(2) starloc(1) merge
regress sorting religiosity01 pid3 pidxrelig white_evang prot cath jew secu interest abortion govspend sophistication male white black age educ7cat oldsouth[pweight= vcf0010z] if year==1994, robust
outreg, se bdec(2) starloc(1) merge
regress sorting religiosity01 pid3 pidxrelig white_evang prot cath jew secu interest abortion govspend sophistication male white black age educ7cat oldsouth[pweight= vcf0010z] if year==1996, robust
outreg, se bdec(2) starloc(1) merge
regress sorting religiosity01 pid3 pidxrelig white_evang prot cath jew secu interest abortion govspend sophistication male white black age educ7cat oldsouth[pweight= vcf0010z] if year==2000, robust
outreg, se bdec(2) starloc(1) merge
regress sorting religiosity01 pid3 pidxrelig white_evang prot cath jew secu interest abortion govspend sophistication male white black age educ7cat oldsouth[pweight= vcf0010z] if year==2008, robust
outreg, se bdec(2) starloc(1) merge
regress sorting religiosity01 pid3 pidxrelig white_evang prot cath jew secu interest abortion govspend sophistication male white black age educ7cat oldsouth[pweight= vcf0010z] if year==2012, robust
outreg, se bdec(2) starloc(1) merge
****2004, 2016 estimates generated separately in respective .dta files...see README in "figure 3" folder

*figure
regress sorting religiosity01 white_evang prot cath jew secu interest   abortion govspend sophistication male white black age educ7cat oldsouth [pweight= vcf0010z] if year==1984 & pid3==1, robust
quietly margins, at(religiosity01)
est store m1984d
regress sorting religiosity01 white_evang prot cath jew secu interest   abortion govspend sophistication male white black age educ7cat oldsouth [pweight= vcf0010z] if year==1984 & pid3==3, robust
margins, at(religiosity01)
est store m1984r
regress sorting religiosity01 white_evang prot cath jew secu interest   abortion govspend sophistication male white black age educ7cat oldsouth [pweight= vcf0010z] if year==1988 & pid3==1, robust
quietly margins, at(religiosity01)
est store m1988d
regress sorting religiosity01 white_evang prot cath jew secu interest   abortion govspend sophistication male white black age educ7cat oldsouth [pweight= vcf0010z] if year==1988 & pid3==3, robust
quietly margins, at(religiosity01)
est store m1988r
regress sorting religiosity01 white_evang prot cath jew secu interest   abortion govspend sophistication male white black age educ7cat oldsouth [pweight= vcf0010z] if year==1992 & pid3==1, robust
quietly margins, at(religiosity01)
est store m1992d
regress sorting religiosity01 white_evang prot cath jew secu interest   abortion govspend sophistication male white black age educ7cat oldsouth [pweight= vcf0010z] if year==1992 & pid3==3, robust
quietly margins, at(religiosity01)
est store m1992r
regress sorting religiosity01 white_evang prot cath jew secu interest   abortion govspend sophistication male white black age educ7cat oldsouth [pweight= vcf0010z] if year==1994 & pid3==1, robust
quietly margins, at(religiosity01)
est store m1994d
regress sorting religiosity01 white_evang prot cath jew secu interest   abortion govspend sophistication male white black age educ7cat oldsouth [pweight= vcf0010z] if year==1994 & pid3==3, robust
quietly margins, at(religiosity01)
est store m1994r
regress sorting religiosity01 white_evang prot cath jew secu interest   abortion govspend sophistication male white black age educ7cat oldsouth [pweight= vcf0010z] if year==1996 & pid3==1, robust
quietly margins, at(religiosity01)
est store m1996d
regress sorting religiosity01 white_evang prot cath jew secu interest   abortion govspend sophistication male white black age educ7cat oldsouth [pweight= vcf0010z] if year==1996 & pid3==3, robust
quietly margins, at(religiosity01)
est store m1996r
regress sorting religiosity01 white_evang prot cath jew secu interest   abortion govspend sophistication male white black age educ7cat oldsouth [pweight= vcf0010z] if year==2000 & pid3==1, robust
quietly margins, at(religiosity01)
est store m2000d
regress sorting religiosity01 white_evang prot cath jew secu interest   abortion govspend sophistication male white black age educ7cat oldsouth [pweight= vcf0010z] if year==2000 & pid3==3, robust
quietly margins, at(religiosity01)
est store m2000r
regress sorting religiosity01 white_evang prot cath jew secu interest   abortion govspend sophistication male white black age educ7cat oldsouth [pweight= vcf0010z] if year==2008 & pid3==1, robust
quietly margins, at(religiosity01)
est store m2008d
regress sorting religiosity01 white_evang prot cath jew secu interest   abortion govspend sophistication male white black age educ7cat oldsouth [pweight= vcf0010z] if year==2008 & pid3==3, robust
quietly margins, at(religiosity01)
est store m2008r
regress sorting religiosity01 white_evang prot cath jew secu interest   abortion govspend sophistication male white black age educ7cat oldsouth [pweight= vcf0010z] if year==2012 & pid3==1, robust
quietly margins, at(religiosity01)
est store m2012d
regress sorting religiosity01 white_evang prot cath jew secu interest   abortion govspend sophistication male white black age educ7cat oldsouth [pweight= vcf0010z] if year==2012 & pid3==3, robust
quietly margins, at(religiosity01)
est store m2012r


********************************************************************************
*table A3 / figure 4 - me of religiosity by denom
********************************************************************************

*table
regress sorting religiosity01 white_evang weXrelig prot protXrelig secu secuXrelig cath cathXrelig jew interest abortion govspend sophistication male white black age educ7cat oldsouth _88  _92  _94  _96  _00  _08  _12 [pweight= vcf0010z], robust
*alternative sorting item
regress sortingalt religiosity01 white_evang weXrelig prot protXrelig secu secuXrelig cath cathXrelig jew interest abortion govspend sophistication male white black age educ7cat oldsouth _88  _92  _94  _96  _00  _08  _12 [pweight= vcf0010z], robust

*figure
*white evangelical
regress sorting religiosity01 interest housemaj abortion govspend sophistication male white black age educ7cat oldsouth _88  _92  _94  _96  _00 _08  _12 [pweight= vcf0010z] if whiteevangelical==1, robust  
quietly margins, at(religiosity01)
est store we

*catholic
regress sorting religiosity01 interest housemaj abortion govspend sophistication male white black age educ7cat oldsouth _88  _92  _94  _96  _00 _08  _12 [pweight= vcf0010z] if catholic==1, robust  
quietly margins, at(religiosity01)
est store cath

*mainline protestant
regress sorting religiosity01 interest housemaj abortion govspend sophistication male white black age educ7cat oldsouth _88  _92  _94  _96  _00 _08  _12 [pweight= vcf0010z] if mainline==1, robust  
quietly margins, at(religiosity01)
est store ml

*secular
regress sorting religiosity01 interest housemaj abortion govspend sophistication male white black age educ7cat oldsouth _88  _92  _94  _96  _00 _08  _12 [pweight= vcf0010z] if secular==1, robust  
quietly margins, at(religiosity01)
est store sec

*stitching separate estimates into one graphic:
coefplot we ml cath sec, drop(_cons interest housemaj abortion govspend sophistication male white black age educ7cat oldsouth _88  _92  _94  _96  _00 _08  _12 ) ylabel(.7 "White evangelical" .9 "Protestant" 1.1 "Catholic" 1.3 "Secular", labcolor(black*.9)) yline(.7 .9 1.1 1.3, lcolor(white) lp(solid)) legend(off) nokey xlin(0) xtitle("Marginal effect") ciopts(lwidth(*3)) msize(medium) ci(90 95)


********************************************************************************
*table A4 / figure 5 - 3-way interactions
********************************************************************************

drop 
 
*table
regress sorting religiosity01 pid3 white_evang pidXrelig weXpid weXrelig weXpidXrelig prot cath secu jew interest abortion govspend sophistication male white black age educ7cat oldsouth _88  _92  _94  _96  _00  _08  _12 [pweight= vcf0010z], robust
outreg, se bdec(2) starloc(1) replace
regress sorting religiosity01 pid3 prot pidXrelig protXpid protXrelig protXpidXrelig cath secu white_evang jew interest abortion govspend sophistication male white black age educ7cat oldsouth _88  _92  _94  _96  _00  _08  _12 [pweight= vcf0010z], robust
outreg, se bdec(2) starloc(1) merge
regress sorting religiosity01 pid3 cath pidXrelig cathXpid cathXrelig cathXpidXrelig secu white_evang prot jew interest abortion govspend sophistication male white black age educ7cat oldsouth _88  _92  _94  _96  _00  _08  _12 [pweight= vcf0010z], robust
outreg, se bdec(2) starloc(1) merge
regress sorting religiosity01 pid3 secu pidXrelig secuXpid secuXrelig secuXpidXrelig white_evang prot cath jew interest abortion govspend sophistication male white black age educ7cat oldsouth _88  _92  _94  _96  _00  _08  _12 [pweight= vcf0010z], robust
outreg, se bdec(2) starloc(1) merge

cd "E:\ssq\figures"
*figure
****3-way white evangelical
regress sorting c.religiosity01##white_evang##pid3 secu prot jew cath interest sophistication abortion govspend male white black age educ7cat oldsouth _88  _92  _94  _96  _00 _08  _12 [pweight= vcf0010z], robust
quietly margins, at(white_evang=1 religiosity01=(0.05(.09).95) pid3=(1,3))
marginsplot, level(95) yline(.5, lcolor(white) lp(solid)) recastci(rarea) ci1opts(fcolor(blue*.5) lcolor(blue)) ci2opts(fcolor(red*.5) lcolor(red)) plot1opts(mcolor(blue) lcolor(blue)) plot2opts(mcolor(red) lcolor(red)) plot( , label("Left-leaning" "Right-leaning")) addplot(hist religiosity01 if white_evang==1, bcolor(white) lcolor(black) bin(10) percent yaxis(2) yscale(alt axis(2)) xlabel(.05 "1" .15 "2" .25 "3" .35 "4" .45 "5" .55 "6" .65 "7" .75 "8" .85 "9" .95 "10", labcolor(black*.9)) ylabel(0 "0%" 20 "20%" 40 "40%" 60 " " 80 " " 100 " " 120 " " 140 " ", labcolor(black*.9) axis(2)) ytitle(" ", axis(2))  fcolor(white) lcolor(black)) ylabel(0 .1 .2 .3 .4 .5, labcolor(black*.9) axis(1)) xtitle("Religiosity (deciles)", axis(1)) ytitle("Estimated sorting", axis(1)) title("White evangelical") saving("Figure 5 - white evangelical", replace)

****mainline prot
regress sorting c.religiosity01##prot##pid3 secu white_evang jew cath interest sophistication abortion govspend male white black age educ7cat oldsouth _88  _92  _94  _96  _00 _08  _12 [pweight= vcf0010z], robust
quietly margins, at(prot=1 religiosity01=(0.05(.09).95)  pid3=(1,3))
marginsplot, level(95) yline(.5, lcolor(white) lp(solid)) recastci(rarea) ci1opts(fcolor(blue*.5) lcolor(blue)) ci2opts(fcolor(red*.5) lcolor(red)) plot1opts(mcolor(blue) lcolor(blue)) plot2opts(mcolor(red) lcolor(red)) plot( , label("Left-leaning" "Right-leaning")) addplot(hist religiosity01 if prot==1, bcolor(white) lcolor(black) bin(10) percent yaxis(2) yscale(alt axis(2)) xlabel(.05 "1" .15 "2" .25 "3" .35 "4" .45 "5" .55 "6" .65 "7" .75 "8" .85 "9" .95 "10", labcolor(black*.9)) ylabel(0 "0%" 20 "20%" 40 "40%" 60 " " 80 " " 100 " " 120 " " 140 " ", labcolor(black*.9) axis(2)) ytitle(" ", axis(2))  fcolor(white) lcolor(black)) ylabel(0 .1 .2 .3 .4 .5, labcolor(black*.9) axis(1)) xtitle("Religiosity (deciles)") ytitle("Estimated sorting", axis(1)) title("Protestant") saving("Figure 5 - protestant", replace)

****catholic
regress sorting c.religiosity01##cath##pid3 secu white_evang jew prot interest sophistication abortion govspend male white black age educ7cat oldsouth _88  _92  _94  _96  _00 _08  _12 [pweight= vcf0010z], robust
quietly margins, at(cath=1 religiosity01=(0.05(.09).95)  pid3=(1,3))
marginsplot, level(95) yline(.5, lcolor(white) lp(solid)) recastci(rarea) ci1opts(fcolor(blue*.5) lcolor(blue)) ci2opts(fcolor(red*.5) lcolor(red)) plot1opts(mcolor(blue) lcolor(blue)) plot2opts(mcolor(red) lcolor(red)) plot( , label("Left-leaning" "Right-leaning")) addplot(hist religiosity01 if cath==1, bcolor(white) lcolor(black) bin(10) percent yaxis(2) yscale(alt axis(2)) xlabel(.05 "1" .15 "2" .25 "3" .35 "4" .45 "5" .55 "6" .65 "7" .75 "8" .85 "9" .95 "10", labcolor(black*.9)) ylabel(0 "0%" 20 "20%" 40 "40%" 60 " " 80 " " 100 " " 120 " " 140 " ", labcolor(black*.9) axis(2)) ytitle(" ", axis(2))  fcolor(white) lcolor(black)) ylabel(0 .1 .2 .3 .4 .5, labcolor(black*.9) axis(1)) xtitle("Religiosity (deciles)") ytitle("Estimated sorting", axis(1)) title("Catholic") saving("Figure 5 - catholic", replace)

****secular
regress sorting c.relig10##secu##pid3 cath white_evang jew prot interest sophistication abortion govspend male white black age educ7cat oldsouth _88  _92  _94  _96  _00 _08  _12 [pweight= vcf0010z], robust 
quietly margins, at(sec=1 relig10=(0(.11).67) pid3=(1,3))
marginsplot, level(95) yline(.5, lcolor(white) lp(solid)) recastci(rarea) ci1opts(fcolor(blue*.5) lcolor(blue)) ci2opts(fcolor(red*.5) lcolor(red)) plot1opts(mcolor(blue) lcolor(blue)) plot2opts(mcolor(red) lcolor(red)) plot( , label("Left-leaning" "Right-leaning")) addplot(hist relig10 if secu==1, bcolor(white) lcolor(black) discr percent yaxis(2) yscale(alt axis(2)) xlabel(.00 "1" .11 "2" .22 "3" .33 "4" .44 "5" .55 "6" .66 "7" .77 "8" .88 "9" .99 "10", labcolor(black*.9)) ylabel(0 "0%" 20 "20%" 40 "40%" 60 " " 80 " " 100 " " 120 " " 140 " ", labcolor(black*.9) axis(2)) ytitle(" ", axis(2))  fcolor(white) lcolor(black)) ylabel(0 .1 .2 .3 .4 .5, labcolor(black*.9) axis(1)) xtitle("Religiosity (deciles)") ytitle("Estimated sorting", axis(1)) title("Secular") saving("Figure 5 - secular", replace)

